package com.esunny.resourcevisualization.controller;

import com.esunny.resourcevisualization.domain.entity.ResourceTypeField;
import com.esunny.resourcevisualization.domain.request.ResourceTypeFieldDto;
import com.esunny.resourcevisualization.domain.response.ReturnStructure;
import com.esunny.resourcevisualization.service.ResourceTypeFieldService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @version 1.0.0.0
 * @ClassName ResourceTypeFieldController
 * @Description 资源类别字段控制层接口
 * @Author baochencong
 * @Date 2020/9/30 16:12
 */
@Controller
@RequestMapping("/resource")
public class ResourceTypeFieldController {

    @Resource
    private ResourceTypeFieldService resourceTypeFieldService;

    private static Logger LOGGER = LoggerFactory.getLogger(ResourceTypeFieldController.class);

    /**
     * 添加资源类别字段
     *
     * @param resourceTypeField 资源类别字段信息
     * @return 添加结果信息
     */
    @ResponseBody
    @PostMapping("/addResourceTypeField")
    public ReturnStructure addResourceTypeField(@RequestBody ResourceTypeField resourceTypeField) {
        if (resourceTypeField == null) {
            LOGGER.info("添加资源类别字段时参数为null");
            return ReturnStructure.NOT_FOUND();
        }
        return resourceTypeFieldService.addResourceTypeField(resourceTypeField);
    }

    /**
     * 添加资源类别字段
     *
     * @param resourceTypeFieldDto 资源类别字段信息列表
     * @return 添加结果信息
     */
    @ResponseBody
    @PostMapping("/addResourceTypeFieldList")
    public ReturnStructure addResourceTypeFieldList(@RequestBody ResourceTypeFieldDto resourceTypeFieldDto) {
        if (resourceTypeFieldDto == null) {
            return ReturnStructure.NOT_FOUND();
        }
        return resourceTypeFieldService.addResourceTypeFieldList(resourceTypeFieldDto.getResourceTypeFieldList());
    }

    /**
     * 通过资源类别字段id删除资源类别字段信息
     *
     * @param fieldId 资源类别字段id
     * @return 删除资源类别字段结果信息
     */
    @ResponseBody
    @PostMapping("/deleteResourceTypeFieldByFieldId")
    public ReturnStructure deleteResourceTypeFieldByFieldId(@RequestParam("fieldId") int fieldId) {
        if (StringUtils.isBlank(fieldId + "")) {
            return ReturnStructure.NOT_FOUND();
        }
        return resourceTypeFieldService.deleteResourceTypeFieldByFieldId(fieldId);
    }

    /**
     * 通过资源类别字段id修改资源类别字段信息
     *
     * @param resourceTypeField 资源类别字段信息
     * @return 修改结果信息
     */
    @ResponseBody
    @PostMapping("/updateResourceTyprFieldByFieldId")
    public ReturnStructure updateResourceTyprFieldByFieldId(@RequestBody ResourceTypeField resourceTypeField) {
        if (resourceTypeField == null) {
            return ReturnStructure.NOT_FOUND();
        }
        return resourceTypeFieldService.updateResourceTyprFieldByFieldId(resourceTypeField);
    }

    /**
     * 通过资源类别字段id获取资源类别字段信息
     *
     * @param fieldId 资源类别字段id
     * @return 资源类别字段信息
     */
    @ResponseBody
    @GetMapping("/getResourceTypeFieldByFieldId/{fieldId}")
    public ReturnStructure getResourceTypeFieldByFieldId(@PathVariable("fieldId") int fieldId) {
        if (StringUtils.isBlank(fieldId + "")) {
            return ReturnStructure.NOT_FOUND();
        }
        return ReturnStructure.SUCCESS("获取资源类别字段信息成功", resourceTypeFieldService.getResourceTypeFieldByField(fieldId));
    }

    /**
     * 通过资源类别英文名获取资源类别字段信息列表
     *
     * @param name 资源类别英文名
     * @return 资源类别字段信息列表
     */
    @ResponseBody
    @GetMapping("/getResourceTypeFieldByName/{name}")
    public ReturnStructure getResourceTypeFieldByName(@PathVariable("name") String name) {
        if (StringUtils.isBlank(name)) {
            return ReturnStructure.NOT_FOUND();
        }
        return ReturnStructure.SUCCESS("获取资源类别字段信息成功", resourceTypeFieldService.getResourceTypeFieldByName(name));
    }

    /**
     * 通过资源类别英文名和资源类别字段英文名获取资源类别字段信息
     *
     * @param name      资源类别英文名
     * @param fieldName 资源类别字段英文名
     * @return 资源类别字段信息
     */
    @ResponseBody
    @GetMapping("/getResourceTypeFieldByNameAndFieldName/{name}/{fieldName}")
    public ReturnStructure getResourceTypeFieldByNameAndFieldName(@PathVariable("name") String name, @PathVariable("fieldName") String fieldName) {
        if (StringUtils.isBlank(name) || StringUtils.isBlank(fieldName)) {
            return ReturnStructure.NOT_FOUND();
        }
        return ReturnStructure.SUCCESS("获取资源类别字段信息成功", resourceTypeFieldService.getResourceTypeFieldByNameAndFieldName(name, fieldName));
    }
}
